package dang.dao.impl;

import org.hibernate.Session;

import dang.dao.UserDao;
import dang.entity.User;
import dang.exception.DangException;

public class UserDaoImpl extends DangDaoImpl implements UserDao {
	@Override
	public User findByEmail(String email) throws DangException{
		Session s = getSession();
		String hql="from User u where u.email=?";
		User u =(User) s.createQuery(hql).setString(0, email).uniqueResult();
		return u;
	}

	@Override
	public User findById(int id) throws DangException {
		Session s =getSession();
		User u =(User) s.get(User.class, id);
		return u;
	}
	@Override
	public void save(User user) throws DangException  {
		Session s = getSession();
		Integer id=(Integer) s.save(user);//返回生成的ID
		user.setId(id);
	}

	@Override
	public void update(User user) throws DangException {
		Session s = getSession();
		s.saveOrUpdate(user);
	}


}
